package week7;

class Professor implements Cloneable {
    String name;

    Professor(String name) {
        this.name = name;
    }

    public Object clone() {
        Object o = null;
        try {
            o = super.clone();
        } catch (CloneNotSupportedException e) {
            System.out.println(e);
        }
        return o;
    }
}

class Student implements Cloneable {
    String name;
    int ID;
    Professor p;

    Student(String name, int ID, Professor p) {
        this.name = name;
        this.ID = ID;
        this.p = p;
    }

    public Object clone() {
        Student o = null;
        try {
            o = (Student) super.clone();
        } catch (CloneNotSupportedException e) {
            System.out.println(e);
        }
        o.p = (Professor) p.clone();
        return o;
    }
}

public class Person4 {
    public static void main(String args[]) {
        Professor p = new Professor("Lee");
        Student s1 = new Student("Justin",20150001, p);
        Student s2 = (Student) s1.clone();
        s2.p.name = "Lucy";
        System.out.println(s1);
        System.out.println(s2);
        System.out.println("p.getName().hashCode() : " + s1.p.name.hashCode());
        System.out.println("p4.getName().hashCode() : " + s2.p.name.hashCode());
        String result = s1.p.name.hashCode() == s2.p.name.hashCode() ? "浅拷贝" : "深拷贝";
        System.out.println(result);
    }
}